'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.simpleSet = undefined;

var _typeof2 = require('babel-runtime/helpers/typeof');

var _typeof3 = _interopRequireDefault(_typeof2);

var _isNumberString = require('./isNumberString');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var simpleSet = exports.simpleSet = function simpleSet(obj, path, val) {
    if (typeof path === 'string') {
        path = path.split('.');
    }
    var now = obj;
    var prev = obj;
    var key = void 0;
    for (var i = 0; i < path.length - 1; i++) {
        key = path[i];
        prev = now;
        now = now[key];
        if (now === null || now === undefined || (typeof now === 'undefined' ? 'undefined' : (0, _typeof3.default)(now)) !== 'object') {
            prev[key] = (0, _isNumberString.isNumberString)(key) ? [] : {};
            now = prev[key];
        }
    }
    now[path[path.length - 1]] = val;
};
exports.default = simpleSet;